package ar.edu.sccs.entities;

import java.io.Serializable;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

public class Dimension implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Object value;
	private Integer type;
	private Boolean semantic;
	private Double similarity;
	private Double weight;

	@Override
	public String toString() {
		return ReflectionToStringBuilder.reflectionToString(this, ToStringStyle.SIMPLE_STYLE);
	}

	public Dimension() {
		super();
	}

	/**
	 * 
	 * @param value
	 */
	public Dimension(Object value) {
		super();
		this.value = value;
	}

	/**
	 * @param similarity
	 * @param value
	 */
	public Dimension(Double similarity, Object value) {
		super();
		this.similarity = similarity;
		this.value = value;
	}

	/**
	 * @param semantic
	 * @param weight
	 * @param type
	 * @param value
	 */
	public Dimension(Boolean semantic, Double weight, Integer type, Object value) {
		super();
		this.semantic = semantic;
		this.weight = weight;
		this.type = type;
		this.value = value;
	}

	/**
	 * @param type
	 * @param semantic
	 * @param weight
	 */
	public Dimension(Integer type, Boolean semantic, Double weight) {
		super();
		this.type = type;
		this.semantic = semantic;
		this.weight = weight;
// Se elimina por caso de ClassType no especificado que siempre tiene 2 opciones: Class o Interface pero no ""
//		if (type != Constants.Dimension.Type.BOOLEAN)
//			this.value = "";
	}

	/**
	 * @return the value
	 */
	public Object getValue() {
		return value;
	}

	/**
	 * @param value the value to set
	 */
	public void setValue(Object value) {
		this.value = value;
	}

	/**
	 * @return the type
	 */
	public Integer getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(Integer type) {
		this.type = type;
	}

	/**
	 * @return the semantic
	 */
	public Boolean getSemantic() {
		return semantic;
	}

	/**
	 * @param semantic the semantic to set
	 */
	public void setSemantic(Boolean semantic) {
		this.semantic = semantic;
	}

	/**
	 * @return the similarity
	 */
	public Double getSimilarity() {
		return similarity;
	}

	/**
	 * @param similarity the similarity to set
	 */
	public void setSimilarity(Double similarity) {
		this.similarity = similarity;
	}

	/**
	 * @return the weight
	 */
	public Double getWeight() {
		return weight;
	}

	/**
	 * @param weight the weight to set
	 */
	public void setWeight(Double weight) {
		this.weight = weight;
	}

	public void setStringValue(String value) {
		this.value = value;
	}

	public String getStringValue() {
		return this.value == null ? null : this.value.toString();
	}

	public void setBooleanValue(Boolean value) {
		this.value = value;
	}

	public void setBooleanValue(boolean value) {
		setBooleanValue(new Boolean(value));
	}

	public void setBooleanValue(int value) {
		switch (value) {
		case 0:
			this.value = null;
			break;
		case 1:
			setBooleanValue(true);
			break;
		case 2:
			setBooleanValue(false);
			break;
		default:
			this.value = null;
			break;
		}
	}

	public void setBooleanValue(String value) {
		if (value == null)
			this.value = null;
		else if(value.equals(1) || value == "1")
			setBooleanValue(true);
		else if(value.equals(2) || value == "2")
			setBooleanValue(false);
		else
			try {
				this.value = new Boolean(value);
			} catch (Exception e) {
				this.value = null;
			}
	}

	public Boolean getBooleanValue() {
		return this.value == null ? null : ((Boolean) this.value).booleanValue();
	}
}
